package org.teiid.translator.cassandra;

import javax.resource.cci.ConnectionFactory;

import org.teiid.core.BundleUtil;
import org.teiid.language.QueryExpression;
import org.teiid.language.Select;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.RuntimeMetadata;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.ExecutionFactory;
import org.teiid.translator.ResultSetExecution;
import org.teiid.translator.Translator;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.TranslatorProperty;
import org.teiid.translator.cassandra.execution.CassandraQueryExecution;
import org.teiid.translator.cassandra.metadata.CassandraMetadataProcessor;

/**
 * 
 * @author Kouba
 *
 */
@Translator(name = "cassandra", description = "A translator for Cassandra NoSql database")
public class CassandraExecutionFactory extends ExecutionFactory<ConnectionFactory, CassandraConnection> {
	public static final BundleUtil UTIL = BundleUtil.getBundleUtil(CassandraExecutionFactory.class);

	@Override
	public void start() throws TranslatorException {
		super.start();
		LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Cassandra ExecutionFactory Started"); //$NON-NLS-1$
	}

	@Override
	public ResultSetExecution createResultSetExecution(QueryExpression command,
			ExecutionContext executionContext, RuntimeMetadata metadata,
			CassandraConnection connection) throws TranslatorException {
		return new CassandraQueryExecution((Select) command, connection, executionContext);
	}
	
	

	@Override
	public void getMetadata(MetadataFactory metadataFactory,
			CassandraConnection conn) throws TranslatorException {
			CassandraMetadataProcessor processor = new CassandraMetadataProcessor(metadataFactory, conn.keyspaceInfo());
			processor.processMetadata();
	}

	@Override
	public boolean supportsOrderBy() {
		return true;
	}

	@Override
	public boolean supportsAggregatesCountStar() {
		return true;
	}

	@Override
	public boolean supportsCompareCriteriaEquals() {
		return true;
	}

	@Override
	public boolean supportsCompareCriteriaOrdered() {
		return true;
	}

	@Override
	public boolean supportsInCriteria() {
		return true;
	}

	@Override
	public boolean supportsRowLimit() {
		return true;
	}
	
	
}
